Lua public Attributes & functions
helloz 4/3/2024 Unity3d
Attributes
transform | UnityEngine.Transform property of lua script binding object |
---|---|
gameObject | UnityEngine.GameObject property of lua script binding object |
Lua public functions
link: lua functions
functions | parameter | describe |
---|---|---|
regist(luafuntion) | lua function | When the game starts, the lunfunction callback will be triggered |
getGameId() | return: string | get game id |
write(key,data,issync) | key: any type,custom | key Make sure it is unique, otherwise it will overwrite the data Data sharing pool, users can store, interact, etc. according to their own preferences. Network synchronization is still in development |
data: any type, the suggestion is table | ||
issync: Boolean, true: network sync | ||
read(key) | key: any type,custom return: bool,data | Read the data in the shared pool and return the result if it exists. Return value: 1. bool type, if true, it means that data exists 2. Data |
isController(key) | key: any type return: bool | When detecting the synchronization object, whether it is the controller, for example, to determine the control of a pirate, if it is True, you can write code according to your preferences, Developing |
getRoomRecords(luafunction) | function | The game is initialized to obtain the basic synchronization information of the game from the server, which will be stored in the data sharing pool by default and can be read through read(key) Developing |
isResReady() | (Currently suitable for unity editor developers, test use) After the game is in, the resource manager has not been initialized, you can use it to detect, | |
IsNil(object) | 1. UnityEngine.Object return: bool | Data type: Gameobject or Transfrom, any type of Unity object, will return true if null |
IsExist(gameobject) | 1. UnityEngine.Object return: bool | Data type: Gameobject or Transfrom, any type of Unity object |
example 1
function Start()
regist(Main)
end
gameId =0
--start game,The only one in the game.(游戏中唯一的.)
function Main()
print('----------------Main---------------------')
gameId = getGameId()
--Get server configuration table (获取服务器配置表)
getRoomRecords(onGetRoomRecords)
end
function onGetRoomRecords()
--assetbundle, Ready to start dynamic loading,准备就绪,可以启动动态加载
if isResReady() then
loadDefUI()
end
end
function loadDefUI()
loadAsync("UI/UIPrefab/UITaskLinePanel",onLoadFinished)
end
function onLoadFinished(prefab)
--校验prefab存在的情况
--[[
if IsNil(prefab) then
end
]]]
if IsExist(prefab) then
local go = newObject(prefab)
go.name = prefab.name
local tf = go.transform
local rectTf = go:GetComponent(typeof(UnityEngine.RectTransform))
tf:SetParent(transform:UIroot())
tf.localScale = Vector3.one
tf.localEulerAngles = Vector3.zero
rectTf.sizeDelta = Vector2.zero
rectTf.anchorMin = Vector2.zero
rectTf.anchorMax = Vector2.one
rectTf.anchoredPosition = Vector2.zero
rectTf.anchoredPosition3D = Vector3.zero
end
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
example2
Use the name of the object as the key to store the position, rotation, and scale information
function getObject()
local isok,data= read(transform.name)
if isok then
transform.position = Vector3(data['x'],data['y'],data['z'])
transform.eulerAngles =Vector3(data['x1'],data['y1'],data['z1'])
transform.scale =Vector3(data['x2'],data['y2'],data['z2'])
end
end
function setObject()
local pos = transform.position
local eul = transform.eulerAngles
local scale = transform.localScale
local data ={}
data['x'] =pos.x
data['y'] =pos.y
data['z'] =pos.z
data['x1'] =eul.x
data['y1'] =eul.y
data['z1'] =eul.z
data['x2'] =scale.x
data['y2'] =scale.y
data['z2'] =scale.z
write(transform.name,data,true)
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25